package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
   private StudentDao studentDao= new StudentDao();
    public boolean addStudent(Student stu) {

        return studentDao.addStudent(stu);
    }

    public boolean isExists(String id) {
       Student[]stus= studentDao.fandAllStudent();
       boolean exists=false;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student!=null&&student.getId().equals(id)){
                exists=true;
                break;
            }
        }
       return exists;
    }

    public Student[] findAllStudent() {
        Student[]stus=studentDao.fandAllStudent();
        boolean flag=false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu!=null){
                flag=true;
                break;
            }
        }
        if (flag){
            return stus;
        }else {
            return null;
        }
    }

    public void deleteStudentById(String delId) {
        studentDao.deleteStudentById(delId);
    }

    public void updateStudent(String updateId, Student newStu) {
        studentDao.updateStudent(updateId,newStu);
    }
}
